<!doctype html>
<html>
<head>
    <meta http-equiv="content-type" content="text/html; charset=UTF-8"/>
    <title>就业岗位信息编辑</title>
    <script src="/webjars/miniui/boot.js" type="text/javascript"></script>
    <link href="/static/css/resource.css" rel="stylesheet" type="text/css"/>
    <script src="/static/js/common/common.js" type="text/javascript"></script>
    <link href="/webjars/miniui/css/demo.css" rel="stylesheet" type="text/css"/>
    <link href="/static/css/default.css" rel="stylesheet" type="text/css"/>
    <style>
        .discell {
            text-align: right;
            width: 300px;
        }
        .input {
            width: 400px;
        }
    </style>
</head>
<body>
<form id="form1" method="post" style="height:100%;width: 100%;overflow-x: auto;overflow-y: auto;">
    <!-- 编辑框START-->
    <div id="editform" class="form" style="padding:10px;">
        <input name="id" id="id" class="mini-hidden" style="width: 100%;" readonly/>
        <input name="createUser" class="mini-hidden" style="width: 100%;" value="${createUser!''}"/>
        <input name="clab" class="mini-hidden" style="width: 100%;" value="${clab!''}"/>
        <input name="clabName" class="mini-hidden" style="width: 100%;" value="${clabName!''}"/>
        <input name="adduserid" class="mini-hidden" style="width: 100%;" value="${adduserid!''}"/>
        <input name="addUserName" class="mini-hidden" style="width: 100%;" value="${addUserName!''}"/>
        <table class="form-table" align="center" cellspacing="8">
            <tr>
                <td class="discell"><font color="#dc143c">*</font>职位名称:</td>
                <td class="input" style="width:240px;">
                    <input name="zwmc" id="zwmc" class="mini-textbox" required="true"/>
                </td>
                <td class="discell"><font color="#dc143c">*</font>公司名称:</td>
                <td class="input" style="width: 400px;">
                    <input name="gsmc" id="zwmc" class="mini-textbox" required="true"/>
                </td>
            </tr>
            <tr>
                <td class="discell"><font color="#dc143c">*</font>职位月薪:</td>
                <td class="input" style="width:240px;">
                    <input name="zwyx" id="zwyx" class="mini-spinner" minValue="0" maxValue="200000" required="true" emptyText="可滚动鼠标滚轮调整"/> 元
                </td>
                <td class="discell"><font color="#dc143c">*</font>招聘人数:</td>
                <td class="input" style="width: 400px;">
                    <input name="zprs" id="zprs" class="mini-spinner" minValue="0" maxValue="200000" required="true" emptyText="可滚动鼠标滚轮调整"/> 人
                </td>
            </tr>
            <tr>
                <td class="discell"><font color="#dc143c">*</font>公司性质:</td>
                <td class="input" style="width:240px;">
                    <input name="gsxz" id="gsxz" class="mini-textbox" required="true"/>
                </td>
                <td class="discell" style="width:120px;"><font color="#dc143c">*</font>公司规模:</td>
                <td class="input" style="width: 400px;">
                    <input name="gsgm" id="gsgm" class="mini-spinner" minValue="0" maxValue="200000" required="true" emptyText="可滚动鼠标滚轮调整"/> 人
                </td>
            </tr>
            <tr>
                <td class="discell"><font color="#dc143c">*</font>经&emsp;&emsp;验:</td>
                <td class="input" style="width:240px;">
                    <input name="jy" id="jy" class="mini-textbox" required="true"/>
                </td>

                <td class="discell"><font color="#dc143c">*</font>学&emsp;&emsp;历:</td>
                <td class="input" style="width: 400px;">
                    <input name="xl" id="xl" class="mini-combobox" required="true"
                           textField="codeName" valueField="codeId" value="90" emptyText="请选择..."
                           url="/azbj/shzzgl/socialOrgInfo/getComboboxData?codeType=2_5"
                    />
                </td>
            </tr>
            <tr>
                <td class="discell"><font color="#dc143c">*</font>发布日期:</td>
                <td class="input" style="width:240px;">
                    <input name="fbrq" id="fbrq" allowInput="false" class="mini-datepicker" ondrawdate="onDrawDate" required="true" />
                </td>
                <td class="discell"><font color="#dc143c">*</font>有&ensp;效&ensp;期:</td>
                <td class="input" style="width: 400px;">
                    <input name="yxq" id="yxq" allowInput="false" class="mini-datepicker" ondrawdate="onDrawDate1" required="true"/>
                </td>
            </tr>
            <tr>
                <td class="discell"><font color="#dc143c">*</font>工作类型:</td>
                <td class="input" style="width:240px;">
                    <input name="leixing" id="leixing" class="mini-combobox" required="true"
                           textField="codeName" valueField="codeId" value="1" emptyText="请选择..."
                           url="/azbj/shzzgl/socialOrgInfo/getComboboxData?codeType=1_88"
                    />
                </td>
                <td class="discell"><font color="#dc143c">*</font>职业技能:</td>
                <td class="input" style="width:240px;">
                    <input name="jinengtype" id="jinengtype" class="mini-combobox" required="true"
                           textField="codeName" valueField="codeId" emptyText="请选择..."
                           url="/azbj/shzzgl/socialOrgInfo/getComboboxData?codeType=4_1"
                    />
                </td>
            </tr>
            <tr>
                <td class="discell"><font color="#dc143c">*</font>公司地址:</td>
                <td colspan="3" style="width: 500px">
                    <input id="province" name="province" class="mini-combobox" emptyText="省份" style="width:120px;"
                           textfield="codeName" valueField="codeId"
                           onclick="onLiveChanged('province')" onvaluechanged="onChanged('province')" required="true"/>
                    <input id="city" name="city" class="mini-combobox" emptyText="市" style="width:120px;"
                           textfield="codeName" valueField="codeId" onclick="onLiveChanged('city')"
                           onvaluechanged="onChanged('city')" required="true"/>
                    <input id="county" name="county" class="mini-combobox" emptyText="县" style="width:120px;"
                           textfield="codeName" valueField="codeId" onclick="onLiveChanged('county')"
                           onvaluechanged="onChanged('county')" required="true"/>
                    <input id="placevill" name="placevill" class="mini-combobox" emptyText="街道" style="width:130px;"
                           textfield="codeName" valueField="codeId"onclick="onLiveChanged('placevill')" required="true"/>
                </td>
            </tr>
            <tr>
                <td class="discell"></td>
                <td colspan="3" style="width: 440px;">
                    <input class="mini-textbox" required="true" style="width: 500px;" emptyText="详细地址" id="gsdd"
                           name="gsdd"/>
                </td>
            </tr>
            <tr>
                <td class="discell"><font color="#dc143c">*</font>帮扶范围:</td>
                <td class="input" style="width:240px;">
                    <input name="bffw"  id="bffw" class="mini-combobox" style="width: 100%" required="true"
                           textField="codeName" valueField="codeId" emptyText="请选择..." onvaluechanged="bffwInputClick()"
                           url="/azbj/bffw/getBffw?flog=${flog}"
                    />
                </td>
                <td class="input" style="width:240px;">
                    <input id="bffwCode" name="bffwCode" class="mini-combobox" required="true" emptyText="下级地区编码" style="width: 84%;"
                           textfield="codeName" valueField="codeId" onvaluechanged="checkBffwCode" multiSelect="true"/>
                </td>
            </tr>
            <tr>
                <td class="discell"><font color="#dc143c">*</font>岗位职责:</td>
                <td colspan="3" style="width: 440px;">
                    <input name="gwzz" id="gwzz" style="width: 500px;height: 80px;" class="mini-textarea"
                           required="true"/>
                </td>
            </tr>
            <tr>
                <td class="discell"><font color="#dc143c">*</font>任职条件:</td>
                <td colspan="3" style="width: 440px;">
                    <input name="rztj" id="rztj" style="width: 500px;height: 80px;" class="mini-textarea"
                           required="true"/>
                </td>
            </tr>
        </table>
    </div>
    <!--编辑框END-->
</form>
<div style="width:100%;line-height: 40px;position: absolute;bottom: 0;border-top: 1px solid #dfdfdf;text-align: center;">
<#if flog!='1'>
    <a class="mini-button" iconCls="fa-save" plain="true" onclick="saveData()">保存</a>
</#if>
    <a class="mini-button" iconCls="fa-close" plain="true" onclick="onCancel()">关闭</a>
</div>
<script type="text/javascript">
    mini.parse();
    var form = new mini.Form("form1");
    var clabName = mini.getByName("clabName").getValue();
    var createUser = mini.getByName("createUser").getValue();
    var clab = mini.getByName("clab").getValue();
    var adduserid = mini.getByName("adduserid").getValue();
    var addUserName = mini.getByName("addUserName").getValue();
    var province = mini.get("province");
    var city = mini.get("city");
    var county = mini.get("county");
    var placevill = mini.get("placevill");
    var gsdd = mini.get("gsdd");
    var bffw = mini.get('bffw');
    var bffwCode = mini.get('bffwCode');
    var bffwCodeData = [{codeId: '-1', codeName: '全区域'}];

    $(document).ready(function () {
        if(bffw.getData()[0].codeId==4){
            $('#bffwCode').hide();
        }
        addressLocking();
    });

    //地址锁定
    function addressLocking(){
        $.ajax({
            url: "/azbj/getAddressLocking",
            type: "GET",
            success: function (res) {
                if(res.level == "06" || res.level == "07" || res.level == "08" || res.level == "03"){
                    province.setData([{"codeId": res.shengCode, "codeName": res.shengName}]);
                    province.setValue(res.shengCode);
                    province.setEnabled(false);
                }
                if(res.level == "07" || res.level == "08" || res.level == "03"){
                    city.setData([{"codeId": res.dishiCode, "codeName": res.dishiName}]);
                    city.setValue(res.dishiCode);
                    city.setEnabled(false);
                }
                if(res.level == "08" || res.level == "03"){
                    county.setData([{"codeId": res.quxianCode, "codeName": res.quxianName}]);
                    county.setValue(res.quxianCode);
                    county.setEnabled(false);
                }
                if(res.level == "03"){
                    placevill.setData([{"codeId": res.jiedaoCode, "codeName": res.jiedaoName}]);
                    placevill.setValue(res.jiedaoCode);
                    placevill.setEnabled(false);
                }
            }
        });
    }


    //标准方法接口定义
    function SetData(data) {
        if(${flog!''}!=1 && !check(data.zwyx)){
            mini.alert("您之前录入的职位月薪为:【"+data.zwyx+"】,不是数字,请重新设置并保存！");
        }
        if(${flog!''}!=1 && !check(data.zprs)){
            mini.alert("您之前录入的招聘人数为:【"+data.zprs+"】,不是数字,请重新设置并保存！");
        }
        if(${flog!''}!=1 && !check(data.gsgm)){
            mini.alert("您之前录入的公司规模为:【"+data.gsgm+"】,不是数字,请重新设置并保存！");
        }
        var o = mini.decode(data);
        form.setData(o);
        form.setChanged(false);
        if (${flog!''}==1) {
            form.setEnabled(false);
        }
        if(data.gsmc!='' && data.gsmc!=undefined ){
            setBffwCode(bffwCode.getValue());
        }
        //设置省市县回显
        province.setData([{"codeId": data.province, "codeName": data.provinceName}]);
        city.setData([{"codeId": data.city, "codeName": data.cityName}]);
        county.setData([{"codeId": data.county, "codeName": data.countyName}]);
        placevill.setData([{"codeId": data.placevill, "codeName": data.placevillName}]);
    }

    function setBffwCode(bffwCodeId){
        bffwCodeData = [{codeId: '-1', codeName: '全区域'}];
        if(bffw.getValue()==1){
            bffwCode.setText('下级地市');
            if(city.getData().length==0){
                onLiveChanged('city')
            }
            bffwCodeData = bffwCodeData.concat(city.getData())
            $('#bffwCode').show();
        }else if(bffw.getValue()==2){
            bffwCode.setText('下级区县');
            if(county.getData().length==0){
                onLiveChanged('county')
            }
            bffwCodeData = bffwCodeData.concat(county.getData())
            $('#bffwCode').show();
        }else if(bffw.getValue()==3) {
            bffwCode.setText('下级街道');
            if(placevill.getData().length==0){
                onLiveChanged('placevill')
            }
            bffwCodeData = bffwCodeData.concat(placevill.getData())
            $('#bffwCode').show();
        }else {
            $('#bffwCode').hide();
        }
        bffwCode.setData(bffwCodeData);
        if(bffwCodeId=='' || bffwCodeId==undefined || bffwCodeId=='无'){
            bffwCode.setValue('-1');
        }
    }

    //检查是否包含-1
    function checkBffwCode(){
        if(bffwCode.getValue().indexOf('-1')!==-1){
            bffwCode.setValue('-1');
        }
    }

    //帮扶范围点击
    function bffwInputClick(){
        if(province.getValue()=='' || city.getValue()=='' || county.getValue()=='' || placevill.getValue()=='' || gsdd.getValue()==''){
            mini.alert('请填写公司地址及详细地址信息');
            mini.get('bffw').setValue(null);
        }else {
            setBffwCode(bffwCode.getValue());
        }
    }

    function saveData() {
        //验证非空字段
        form.validate();
        if (form.isValid() == false ||${flog!''} == 1) {
            return;
        }
        var clabName = mini.getByName("clabName").getValue();
        var data = form.getData();
        //公司人数不能大于公司规模
        if(data.zprs > data.gsgm){
            mini.alert("公司人数不能大于公司规模");
            return;
        }
        //发布日期不能大于有效期
        if(data.fbrq > data.yxq){
            mini.alert("发布日期不能大于有效期");
            return;
        }
        data.createUser = createUser;
        data.clab = clab;
        data.clabName = clabName;
        data.adduserid = adduserid;
        data.addUserName = addUserName;
        var json = mini.encode(data);
        commonSaveData("/azbj/socialemployment", {data: json}, callback);
        // 保存成功的回调函数
        function callback(success) {
            mini.alert("保存成功","成功",window.CloseOwnerWindow);
        }
    }

    //校验数字(带小数点)
    function check(e) {
        var re = /^[1-9][0-9]*([.][0-9]{1,2})?$/;
        if (e != "" && e!=undefined && e!=0) {
            if (!re.test(e)) {
                return false;
            }
            return true;
        }
        return true;
    }

    /**
     * 公司地址
     *     placepro  placecity placecou placevill placenum
     * @param e
     */
    var urltemp = "/azbj/getCodeDetail/?codeType=2_1&codeId=-2";
    function onLiveChanged(e) {
        if("province" == e){
            var value = province.getValue();
            province.setValue("");
            var url =  "/azbj/getCodeDetail/?codeType=2_1&codeId=-1";
            province.setUrl(url);
            if(value!=''){
                province.setValue(value);
            } else {
                province.select(0);
            }
        }
        if("city" == e){
            var value = city.getValue();

            if(province.getValue()==""){
                province.setUrl(urltemp);
                province.setValue("");
                county.setUrl(urltemp);
                county.setValue("");
                placevill.setUrl(urltemp);
                placevill.setValue("");
                return;
            }
            var codeId = province.getValue();
            city.setValue("");
            var url = "/azbj/getCodeDetail/?codeType=2_1&codeId=" + codeId;
            city.setUrl(url);
            if(value!=''){
                city.setValue(value);
            } else {
                city.select(0);
            }
        }
        if("county" == e) {
            var value = county.getValue();

            if(city.getValue()==""){
                county.setUrl(urltemp);
                county.setValue("");
                placevill.setUrl(urltemp);
                placevill.setValue("");
                return;
            }
            var codeId = city.getValue();
            county.setValue("");
            var url = "/azbj/getCodeDetail/?codeType=2_1&codeId=" + codeId;
            county.setUrl(url);
            if(value!=''){
                county.setValue(value);
            } else {
                county.select(0);
            }
        }
        if("placevill" == e){
            var value = placevill.getValue();

            if(county.getValue()==""){
                placevill.setUrl(urltemp);
                placevill.setValue("");
                return;
            }
            var parent_code = county.getValue();
            placevill.setValue("");
            var url = "/azbj/getCodeDetail?codeType=2_1&codeId=" + parent_code;
            placevill.setUrl(url);
            if(value!=''){
                placevill.setValue(value);
            } else {
                placevill.select(0);
            }
        }
    }

    function onChanged(e) {
        if ("province" == e) {
            city.setValue("");
            county.setValue("");
            placevill.setValue("");
        }
        if ("city" == e) {
            county.setValue("");
            placevill.setValue("");
        }
        if ("county" == e) {
            placevill.setValue("");
        }
    }

    //发布日期不能选择比今天靠后的日期
    function onDrawDate(e) {
        var date = e.date;
        var d = new Date();
        //选择的日期大于今天日期 不能选
        if (date.getTime() > d.getTime()) {
            e.allowSelect = false;
        }
    }

    /**
     * 禁止选择今天之前的日期
     * @param e
     */
    function onDrawDate1(e) {
        var date = e.date;
        var d = new Date();
        //一天等于86400000ms
        if (d.getTime()-86400000 > date.getTime()) {
            e.allowSelect = false;
        }
    }
</script>
</body>
</html>